﻿//Write a method ReadNumber(int start, int end) that enters an integer number in given range [start…end].
//If an invalid number or non-number text is entered, the method should throw an exception.
//Using this method write a program that enters 10 numbers: a1, a2, … a10, such that 1 < a1 < … < a10 < 100


using System;

public class IntegerNumbersInGivenRange
{
    public static void Main(string[] args)
    {
        int[] integerArray = new int[10];
        int numberStart = 1;
        int numberEnd = 91;
        for (int i = 0; i < integerArray.Length; i++)
        {
            int number = ReadNumber(numberStart, numberEnd);
            if (number > 0)
            {
                integerArray[i] = number;
                numberStart = number;
                numberEnd++;
            }
            else
            {
                i--;
            }
        }
    }

    private static int ReadNumber(int start, int end)
    {
        Console.WriteLine("Enter integer number greater than {0} and less than {1}!", start, end);
        try
        {
            int number = int.Parse(Console.ReadLine());
            if ((number <= start) || (number >= end))
            {
                throw new ArgumentOutOfRangeException();
            }

            return number;
        }
        catch (FormatException)
        {
            Console.WriteLine("Invalid number!");
            return 0;
        }
        catch (ArgumentOutOfRangeException)
        {
            Console.WriteLine("The number must be greater than {0} and less than {1}!", start, end);
            return 0;
        }
    }
}